package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.vo.RobotStatuPoVo;
import com.hgxd.result.Result;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


import com.hgxd.service.IRobotStatuService;
import com.hgxd.entity.RobotStatu;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 车体设备状态表 前端控制器
 * </p>
 *
 * @author wtf
 * @since 2023-12-01
 */
@Api(tags = "机器人车体设备状态表")
@RestController
@RequestMapping("/api/robot-statu")
public class RobotStatuController {
    @Resource(name = "RobotStatuServiceImpl")
    private IRobotStatuService robotStatuService;
    /**
     * 根据机器人id查询机器人状态
     */
    @PostMapping("/getRobotByRobotId/{robotId}")
    @ApiOperation(value = "根据机器人id查询机器人状态", notes = "根据机器人id查询机器人状态")
    @ApiImplicitParam(name = "robotId", value = "机器人id")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-查询",operType = "查询",operContent = "查询")
    public Result<List<RobotStatu>> getRobotByRobotId(@PathVariable Integer robotId) {
        return Result.ok(robotStatuService.getRobotByRobotId(robotId));
    }
    /**
     * 根据组织查询对应的机器人
     */
    @PostMapping("/getRobotByOrganization/{organizationName}")
    @ApiOperation(value = "根据组织查询对应的机器人", notes = "根据组织查询对应的机器人")
    @ApiImplicitParam(name = "organizationName", value = "组织名称")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-修改",operType = "修改",operContent = "修改")
    public Result<List<RobotStatu>> getRobotByOrganization(@PathVariable String organizationName) {
        return Result.ok(robotStatuService.getRobotByOrganization(organizationName));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "必须传入id")
    @ApiImplicitParam(name = "robotStatu", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-修改",operType = "修改",operContent = "修改")
    public Result<Boolean> update(@RequestBody RobotStatu robotStatu) {
        robotStatu.setUpdateTime(LocalDateTime.now());
        return Result.ok(robotStatuService.updateById(robotStatu));
    }


    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部", notes = "无需传参")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-查询全部",operType = "查询",operContent = "查询全部")
    public Result<List<RobotStatu>> findAll() {
        return Result.ok(robotStatuService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个", notes = "传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-根据id查询一个",operType = "查询",operContent = "根据id查询一个")
    public Result<RobotStatu> findOne(@PathVariable Integer id) {
        return Result.ok(robotStatuService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "传入对应所需参数")
    @OperationLogAnnotation(operModule = "机器人车体设备状态表-分页模糊查询",operType = "查询",operContent = "分页模糊查询")
    public Result<Page<RobotStatu>> findPage(@RequestBody RobotStatuPoVo robotStatuPoVo) {
        LambdaQueryWrapper<RobotStatu> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(!StringUtil.isNullOrEmpty(robotStatuPoVo.getRobotName()),RobotStatu::getRobotName,robotStatuPoVo.getRobotName())
                .eq(!StringUtil.isNullOrEmpty(robotStatuPoVo.getOrganizationName()),RobotStatu::getOrganizationName,robotStatuPoVo.getOrganizationName());
        return Result.ok(robotStatuService.page(new Page<>(robotStatuPoVo.getPageNum(), robotStatuPoVo.getPageSize()), lambdaQueryWrapper));
    }
}

